<?
	//
	require_once("fta.201003310000/fta.php");
	fta_registerModules(
		array(
		//"cms.201003310000/config/cmsConfig",//we will deprecate the old cms config soon..
		//"FTAWebPage/ftaDefaultWidgets",
		
		//"site/components/MAIOrderItem",
		
		"FTACart/FTAOrderItem",
		"FTACart/FTAOrderContainer",			
		//"FTACart/FTACart"
	));	

	class MAIOrderContainer extends FTAOrderContainer {
		
		function MAIOrderContainer(){
			parent::__construct();
			
			
			//hack hack hack test..
			//static $count;
			//if (is_null($count)) $count = -1;
			//
			//$count++;
			
			$this->keys = array_merge_recursive(

				array(
					EXTRACT_BOOLEAN => array ("termsAgree")
				),
				array(
					//EXTRACT_STRING => array("hearAboutUs", "company", "phoneAuckland", "location", "deliveryStreet", "deliverySuburb", "deliveryTime", "repName", "state", "zip")
					EXTRACT_STRING => array("hearAboutUs", "state", "zip", "formsent")
				),
				$this->keys
			);
			
			$this->dataModelKeyMapping = 
				array_merge(
					$this->dataModelKeyMapping,
					array(	
						"hearAboutUs"=>"extra10",
//						"company"=>"author",
//						"phoneAuckland"=>"extra11",
//						"location"=>"extra12",
//						"deliveryStreet"=>"extra13",
//						"deliverySuburb"=>"extra14",
//						"deliveryTime"=>"extra15",
						"formsent"=>"extra8",
						"state"=>"extra6",
						"zip"=>"extra7"
						
					)
			);
			
			$this->requiredKeys = array(
				'termsAgree',
			    'firstName',
			    'lastName',
				'email',
				"verifyEmail",
				'phone',
				"street",
				"city",
				"country",
				"suburb",
				//"state",
				//"deliveryStreet",
				//"deliverySuburb",
				//"deliveryTime"
			);
			
		}
		
		
		function shippingPrice(){
			//return parent::shippingPrice();
			//return "TBA";
			$shippingPrice = '0.00';
			
			foreach ($this->valueForKey('orderItems') as $oi) {
				$product = $oi->getProduct();
				
				if($product->documenttypecode == 'docArtwork'){
					$shippingPrice = "TBA";
				}
			}
			return $shippingPrice;
		}
		
		function price() {
			return parent::price();
		}
		
		function totalPrice(){
			return parent::totalPrice();
		}
		
		function validateEmail(){
			$email = $this->valueForKey('email');
			if (!isEmailAddress($email)){
				return VALIDATION_INVALID_EMAIL_ADDRESS;
			}
			return true;
		}
		
	}
